from greenlet import greenlet
import time

def a():
    while True:
        print('---1---')
        gr2.switch()
        time.sleep(0.5)

def b():
    while True:
        print('---2---')
        gr1.switch()
        time.sleep(0.5)

if __name__ == '__main__':
    gr1 = greenlet(a)
    gr2 = greenlet(b)

    # 切换到gr1执行
    gr1.switch()
